---
layout: "default"
title: "insert"
description: "Swift documentation for 'insert': Insert newElement into x at index i."
keywords: "insert,func,swift,documentation"
root: "/v1.2"
---

<div class="declaration" id="func-insert-c_-rangereplaceablecollectiontype-inout_-c-newelement_-c-generator-element-atindex_-c-index">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-insert-c_-rangereplaceablecollectiontype-inout_-c-newelement_-c-generator-element-atindex_-c-index">func <wbr>insert&lt;C : RangeReplaceableCollectionType&gt;(<wbr>inout:<wbr> C, newElement:<wbr> C.Generator.Element, atIndex: C.Index)</a>
        
<div class="comment collapse" id="comment-func-insert-c_-rangereplaceablecollectiontype-inout_-c-newelement_-c-generator-element-atindex_-c-index"><div class="p">
    <p>Insert <code>newElement</code> into <code>x</code> at index <code>i</code>.</p>

<p>Invalidates all indices with respect to <code>x</code>.</p>

<p>Complexity: O(<code>count(x)</code>).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func insert&lt;C : RangeReplaceableCollectionType&gt;(inout x: C, newElement: C.Generator.Element, atIndex i: C.Index)</code>
    
    
</div></div>
</div>
